import timit_stats as tist
import gesture as ges
import os
import matplotlib.pyplot as plt
%pylab inline
trans_dir = "../USC-TIMIT/EMA/Data/M1/trans"
mat_dir = "../USC-TIMIT/EMA/Data/M1/mat"
gestures = {}
for fname in os.listdir(trans_dir):
fname = os.path.splitext(fname)[0]
t_fname = os.path.join(trans_dir, fname + ".trans")
mat_fname = os.path.join(mat_dir, fname + ".mat")
gest = tist.calc_gestures(mat_fname, t_fname)
for g in gest:
if g not in gestures:
gestures[g] = ges.Gesture(g)
gestures[g].extend(gest[g])
print "gestures calculation finished"
articulators = ["LL", "UL", "TT", "TB", "TD", "JAW"]
cmap = plt.get_cmap('Set3')
colors = [cmap(i) for i in np.linspace(0, 1, len(articulators))]
for g_name, g in gestures.items():
fig1, ax1 = plt.subplots(figsize=(20, 10))
fig1.suptitle("Gesture \"{}\" (samples = {})".format(g_name, len(g.params["LL_x"])), fontsize=20, fontweight='bold')
g_m = g.get_mean()
g_v = g.get_variance()
for i in range(len(articulators)):
a = articulators[i]
a_x = g.params[a+"_x"]
a_y = g.params[a+"_y"]
plt.scatter(a_x, a_y, color=colors[i], alpha=0.5, label=a)
size = g_v[a+"_x"]**2 + g_v[a+"_y"]**2
plt.scatter(g_m[a+"_x"], g_m[a+"_y"],
color="b", alpha=0.5,s=size)
plt.legend(loc='lower left')
plt.show()